/**
 *
 * @param id 元素id
 * @param pageNum 当前页码
 * @param pageSize 页码大小
 * @param pages 总页数
 * @param showPage 最多展示的页码
 */
function  Page() {
    // this.pageNum = pageNum;
    // this.pageSize= pageSize;
    // this.pages = pages;
    // this.showPage = showPage;
    this.createPage = function (selector,pageNum,pageSize,pages,showPage,urlPrefix) {
        if(pages < 2)
            return;
        let html = '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=1&pageSize=' + pageSize + '">首页</a></li>';
        // 总页数超过了最多展示的页码
        if(pages > showPage){
            if((pageNum+1) >= showPage && (pageNum+2 )< pages ) {
                // 前面需要加..
                // 前后的数量展示'+urlPrefix+'
                html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=1&pageSize=' + pageSize + '">1</a></li>';
                html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=2&pageSize=' + pageSize + '">2</a></li>';
                html += '<li class="page-item"><a class="page-link nopage" href="javascript:void(0)">...</a> </li>';
                html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=' + (pageNum - 2) + '&pageSize=' + pageSize + '">' + (pageNum - 2) + '</a></li>';
                html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=' + (pageNum - 1) + '&pageSize=' + pageSize + '">' + (pageNum - 1) + '</a></li>';
                html += '<li class="page-item"><a class="page-link active" href="'+urlPrefix+'?pageNum=' + (pageNum) + '&pageSize=' + pageSize + '">' + (pageNum) + '</a></li>';
                if(pageNum+2<pages){
                    html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=' + (pageNum + 1) + '&pageSize=' + pageSize + '">' + (pageNum + 1) + '</a></li>';
                    html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=' + (pageNum + 2) + '&pageSize=' + pageSize + '">' + (pageNum + 2) + '</a></li>';
                } else {
                    for(let i = pageNum+1 ;i < pages; i++){
                        html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=' + i  + '&pageSize=' + pageSize + '">' + i + '</a></li>';
                    }
                }
            } else if( (pageNum+1)  < showPage ){
                for(let i = 0 ; i < showPage ; i++){
                    if((i+1) == pageNum){
                        html += '<li class="page-item"><a class="page-link active" href="'+urlPrefix+'?pageNum='+(i+1)+'&pageSize='+pageSize+'">'+(i+1)+'</a></li>';
                    } else {
                        html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum='+(i+1)+'&pageSize='+pageSize+'">'+(i+1)+'</a></li>';
                    }
                }
            } else {
                html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=1&pageSize=' + pageSize + '">1</a></li>';
                html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum=2&pageSize=' + pageSize + '">2</a></li>';
                html += '<li class="page-item"><a class="page-link nopage" href="javascript:void(0)">...</a> </li>';
                for(let i = (pages-4) ; i <= pages ; i++){
                    if(i == pageNum){
                        html += '<li class="page-item"><a class="page-link active" href="'+urlPrefix+'?pageNum='+i+'&pageSize='+pageSize+'">'+i+'</a></li>';
                    } else {
                        html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum='+i+'&pageSize='+pageSize+'">'+i+'</a></li>';
                    }
                }
            }
        } else {
            for(let i = 1 ; i <= pages ; i++){
                if(i == pageNum){
                    html += '<li class="page-item"><a class="page-link active" href="'+urlPrefix+'?pageNum='+i+'&pageSize='+pageSize+'">'+i+'</a></li>';
                } else {
                    html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum='+i+'&pageSize='+pageSize+'">'+i+'</a></li>';
                }
            }
        }
        html += '<li class="page-item"><a class="page-link" href="'+urlPrefix+'?pageNum='+pages+'&pageSize=' + pageSize + '">尾页</a></li>';
        $(selector).empty().html(html);
    }
}
